package com.miwzn.comm;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: wzn
 * @Date: 2018/6/4 09:20
 * @Description:
 */
public class ResponseEntity extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResponseEntity() {
        put("code", 0);
        put("msg", "success");
    }

    public ResponseEntity(int code,String msg) {
        put("code", code);
        put("msg", msg);
    }


    public ResponseEntity(String msg) {
        put("code", 0);
        put("msg", msg);
    }

    public static ResponseEntity error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static ResponseEntity error(String msg) {
        return error(500, msg);
    }

    public static ResponseEntity error(int code, String msg) {
        ResponseEntity r = new ResponseEntity();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static ResponseEntity success(String msg) {
        return success(0,msg);
    }

    public static ResponseEntity success(int code, String msg) {
        ResponseEntity r = new ResponseEntity();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static ResponseEntity success(Map<String, Object> map) {
        ResponseEntity r = new ResponseEntity();
        r.putAll(map);
        return r;
    }

    public static ResponseEntity success() {
        return new ResponseEntity();
    }

    @Override
    public ResponseEntity put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
